/*
 * @Author: szx
 * @Date: 2022-03-04 14:02:19
 * @LastEditTime: 2022-03-04 14:12:20
 * @Description:
 * @FilePath: \leetcode\100-199\112\112_2.js
 */
/**
 * @param {TreeNode} root
 * @param {number} targetSum
 * @return {boolean}
 */
var hasPathSum = function (root, targetSum) {
    if (!root) return true;
    const target = targetSum - root.val;
    if (!root.left && !root.right) {
        return target == 0;
    }
    return hasPathSum(root.left, target) || hasPathSum(root.right, target);
};
